/**
* Copyright (C) 2018-2020
* All rights reserved, Designed By www.yixiang.co
* 注意：
* 本软件为www.yixiang.co开发研制，未经购买不得使用
* 购买后可获得全部源代码（禁止转卖、分享、上传到码云、github等开源平台）
* 一经发现盗用、分享等行为，将追究法律责任，后果自负
*/
package co.yixiang.mall.biz.shop.controller;
import java.util.Arrays;

import co.yixiang.common.mproot.domain.PageResult;
import co.yixiang.common.mproot.dozer.service.IGenerator;
import co.yixiang.mall.biz.shop.service.YxStoreProductStockValueService;
import co.yixiang.mall.common.shop.domain.YxStoreProductStockValue;
import co.yixiang.mall.common.shop.dto.YxStoreProductStockValueDto;
import co.yixiang.mall.common.shop.dto.YxStoreProductStockValueQueryCriteria;
import co.yixiang.mall.common.shop.dto.YxStoreProductStockVo;
import lombok.AllArgsConstructor;

import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.*;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import co.yixiang.common.log.annotation.Log;
/**
* @author zhuhongjian
* @date 2021-03-17
*/
@Api(tags = "库存查询管理")
@RestController
@RequestMapping("/yxStoreProductStockValue")
public class YxStoreProductStockValueController {

    private final YxStoreProductStockValueService yxStoreProductStockValueService;
    private final IGenerator generator;

    public YxStoreProductStockValueController(YxStoreProductStockValueService yxStoreProductStockValueService, IGenerator generator) {
        this.yxStoreProductStockValueService = yxStoreProductStockValueService;
        this.generator = generator;
    }


    @Log("导出数据")
    @ApiOperation("导出数据")
    @GetMapping(value = "/download")
    @PreAuthorize("hasAnyAuthority('admin','yxStoreProductStockValue:list')")
    public void download(HttpServletResponse response, YxStoreProductStockValueQueryCriteria criteria) throws IOException {
        yxStoreProductStockValueService.download(generator.convert(yxStoreProductStockValueService.queryAll(criteria), YxStoreProductStockValueDto.class), response);
    }

    @GetMapping
    @Log("查询库存查询")
    @ApiOperation("查询库存查询")
    @PreAuthorize("hasAnyAuthority('admin','yxStoreProductStockValue:list')")
    public ResponseEntity<PageResult<YxStoreProductStockVo>> getYxStoreProductStockValues(YxStoreProductStockValueQueryCriteria criteria, Pageable pageable){

        return new ResponseEntity<>(yxStoreProductStockValueService.queryAll(criteria,pageable),HttpStatus.OK);
    }

    @PostMapping
    @Log("新增库存查询")
    @ApiOperation("新增库存查询")
    @PreAuthorize("hasAnyAuthority('admin','yxStoreProductStockValue:add')")
    public ResponseEntity<Object> create(@Validated @RequestBody YxStoreProductStockValue resources){
        return new ResponseEntity<>(yxStoreProductStockValueService.save(resources),HttpStatus.CREATED);
    }

    @PutMapping
    @Log("修改库存查询")
    @ApiOperation("修改库存查询")
    @PreAuthorize("hasAnyAuthority('admin','yxStoreProductStockValue:edit')")
    public ResponseEntity<Object> update(@Validated @RequestBody YxStoreProductStockValue resources){
        yxStoreProductStockValueService.updateById(resources);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }

    @Log("删除库存查询")
    @ApiOperation("删除库存查询")
    @PreAuthorize("hasAnyAuthority('admin','yxStoreProductStockValue:del')")
    @DeleteMapping
    public ResponseEntity<Object> deleteAll(@RequestBody Long[] ids) {
        Arrays.asList(ids).forEach(id->{
            yxStoreProductStockValueService.removeById(id);
        });
        return new ResponseEntity<>(HttpStatus.OK);
    }
}
